/*
* $Id: RenameOperation.cpp 2 2009-12-23 13:58:02Z volok-aleksej@yandex.ru $
*
* Copyright 2009 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "RenameOperation.h"
#include "../Tables/TableNames.h"
#include "../SqlBinder.h"

CRenameOperation::CRenameOperation(){}
CRenameOperation::~CRenameOperation(){}
void CRenameOperation::UpdateValue(IDatabase* pDatabase){
	std::tstring strRequest(_T("UPDATE "));
	std::tstring strNameTable, strId;
	if(m_content.s_type == content::DEFAULT)
		return;
	if(m_content.s_type == content::POINT){
		strNameTable = POINTS_TABLE_NAME;
		strId = _T("id_point");
	} else if(m_content.s_type == content::FAMILY){
		strNameTable = FAMILIES_TABLE_NAME;
		strId = _T("id_family");
	} else if(m_content.s_type == content::HOUSING){
		strNameTable = HOUSINGS_TABLE_NAME;
		strId = _T("id_housing");
	}
	CSqlBinder binder(strRequest + strNameTable + 
		_T(" SET name=? WHERE ") + strId + _T("=?;"));
	binder.SetValue(0, m_content.s_strNewName);
	binder.SetValue(1, m_content.s_nId);
	pDatabase->ExecRequest(binder.GetRequest());
	m_content.Clear();
}

CRenameOperation::content::content(){
	Clear();
}
void CRenameOperation::content::Clear(){
	s_type = DEFAULT;
	s_strNewName.clear();
	s_nId = 0;
}
